package com.example.fms.controller;

import com.example.fms.dto.resp.MenusDto;
import com.example.fms.dto.resp.RightRespDto;
import com.example.fms.service.RightService;
import com.example.fms.vo.ResponseBean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping()
public class RightController {

    @Resource
    private RightService rightService;

    @GetMapping("/rights/{type}")
    public ResponseBean<List<RightRespDto>> getRights(@PathVariable String type) {
        if (type.equals("list")) {
            return ResponseBean.successMeat(rightService.getRights(type));
        } else {
            return ResponseBean.successMeat(rightService.getMenus(-1L,true));
        }
    }

    @GetMapping("/menus/{rid}")
    public ResponseBean<List<MenusDto>> getMenus(@PathVariable Long rid) {
        return ResponseBean.successMeat(rightService.getMenus(rid,false));
    }
}
